<?php

use yii\db\Migration;
use yii\db\Schema;

/**
 * Class m210423_051624_CREATE_DB_TOPIC
 */
class m210423_051624_CREATE_DB_TOPIC extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {

        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';

         // 问答评论信息表 
        $this->createTable('topic', [
            "topic_id" => Schema::TYPE_PK,
            "topic_type" => Schema::TYPE_STRING. "(45) NOT NULL COMMENT '类型'",
            "schoolid" =>   Schema::TYPE_INTEGER. "(12) NOT NULL COMMENT '发表者id'",
            "comment_id" => Schema::TYPE_INTEGER. "(12) NULL COMMENT '评论者id'",
            "topic_com" =>  Schema::TYPE_TEXT. " NOT NULL COMMENT '发表内容'",
            "topic_likes" => Schema::TYPE_INTEGER.  "(5) NULL COMMENT '点赞数'",
            "topic_name" =>  Schema::TYPE_STRING.    "(45) NOT NULL COMMENT '用户名'",
            "create_time"=>     Schema::TYPE_DATETIME.  " NULL",
            "updated_at" =>     Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);


        $this->addColumn('{{detail}}', 'detail_title', Schema::TYPE_STRING. "(256) NOT NULL COMMENT '标题' AFTER detail_id");

        $this->addColumn('{{detail}}', 'detail_top', Schema::TYPE_INTEGER. "(1) DEFAULT '0' COMMENT '置顶' AFTER detai_com");

        $this->alterColumn('{{detail}}', 'detail_type', Schema::TYPE_INTEGER. "(1) DEFAULT '1' COMMENT  '描述类型'");

        $this->alterColumn('{{detail}}', 'detai_com', Schema::TYPE_TEXT. " NULL COMMENT  '描述内容'");


        $this->addColumn('{{detail}}', 'status', Schema::TYPE_INTEGER. "(1) DEFAULT '1' COMMENT '1正常  2禁用' AFTER detail_time");

        $this->addColumn('{{user}}', 'status', Schema::TYPE_INTEGER. "(1) DEFAULT '1' COMMENT '1正常  2禁用' AFTER create_time");
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        echo "m210423_051624_CREATE_DB_TOPIC cannot be reverted.\n";

        return false;
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m210423_051624_CREATE_DB_TOPIC cannot be reverted.\n";

        return false;
    }
    */
}
